from rest_framework import serializers
from myapp.models import User ,ThirdModel

class UserSerializer(serializers.ModelSerializer):
    # 使用 SerializerMethodField 来获取 user_type 的显示名称
    user_type_display = serializers.SerializerMethodField()

    class Meta:
        model = User
        # fields = ['id', 'user_type', 'user_type_display']
        fields = '__all__'

    def get_user_type_display(self, obj):
        # 调用模型的 get_<field_name>_display() 方法获取显示名称
        return obj.get_user_type_display()


class PhoneCodeLoginSerializer(serializers.Serializer):
    phone = serializers.CharField(max_length=11)
    code = serializers.CharField(max_length=4)

class PhonePasswordLoginSerializer(serializers.Serializer):
    phone = serializers.CharField(max_length=11)
    password = serializers.CharField(max_length=20)

class ThirdSerializer(serializers.ModelSerializer):
    class Meta:
        model = ThirdModel
        fields = '__all__'
